/*
 * @Author: LiYu
 * @Date: 2022-04-03 10:35:36
 * @LastEditors: LiYu
 * @LastEditTime: 2022-04-03 20:58:04
 * @Description: 
 */
const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
  mode: "development",
  entry: "./src/index.ts",
  resolve: {
    extensions: ['.ts', '.js', '.json']
  },
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js",
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          "babel-loader",
          "ts-loader"
        ]
      },
      {
        test: /\.less$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                plugins: [
                  [
                    'postcss-preset-env',
                    {
                      browsers: 'last 2 versions'
                    }
                  ]
                ]
              }
            }
          },
          'less-loader'
        ]
      }
    ]
  },
  plugins: [
    // 构建html
    new HTMLWebpackPlugin({
      title: '贪吃蛇',
      template: path.resolve(__dirname,  'index.html')
    }),
    // 删除output目录，默认目录不会被删除
    new CleanWebpackPlugin({
      
    })
  ]
}


